# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=libphonenumber
pkgver=8.13.8
pkgrel=1
epoch=1
pkgdesc="Google's common library for parsing, formatting, and validating international phone numbers"
url="https://github.com/googlei18n/libphonenumber"
arch=(x86_64)
license=(Apache)
depends=(
  abseil-cpp
  icu
  protobuf
)
makedepends=(
  cmake
  git
  gtest
  jre-openjdk-headless
)
_commit=07cd7bbb8a2faf9f2ef7c338e66f2ba303dfad0f  # tags/v8.13.8^0
source=("git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^libphonenumber-\|^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname

  # Fix build with abseil-cpp 2023
  sed -e 's|CMAKE_CXX_STANDARD 11|CMAKE_CXX_STANDARD 17|' -i tools/cpp/CMakeLists.txt
}

build() {
  local cmake_options=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_CXX_STANDARD=17
    -DUSE_BOOST=OFF
    -DUSE_STDMUTEX=ON
  )

  cmake -S $pkgname/cpp -B build "${cmake_options[@]}"
  cmake --build build
}

check() {
  cmake --build build --target tests
}

package() {
  depends+=(libicu{uc,i18n}.so libprotobuf.so)
  provides+=(libgeocoding.so libphonenumber.so)

  DESTDIR="$pkgdir" cmake --install build
}

# vim:set sw=2 sts=-1 et:
